'''
Created on Jul 17, 2009

@author: xin
@author: Mikael Rousson
'''
import numpy
import pylab

def find_significant_lf_patches(samples, threshold):
    """ Finds the indices of the most significant coefficients in vector or
    matrix SAMPLES, based on the variance of each row of this last "samples" 
    must be a column vector or a matrix containing a row for each sample
    "threshold" determines the max variance to eliminate patches (typ=1).
    
    @return 
        Returns a column vector of indices.
    """
    Nx, dim = samples.T.shape
    if threshold > 0:
       samp_var = var(samples)
       significant = pylab.where(samp_var >= threshold)[0]
    else:
        significant = arange(1, Nx + 1).T
    return significant
   
def var(samples):
    columns = samples.shape[1]
    result = []
    for i in range(columns):
        result.append(numpy.var(samples[:, i], ddof=1))
    return numpy.array(result)
